int cmp(int* x, int* y)
{
    return *x - *y;
}

int* fairCandySwap(int* aliceSizes, int aliceSizesSize, int* bobSizes, int bobSizesSize, int* returnSize) {
    int* a = (int*)malloc(sizeof(int) * 2);
    *returnSize = 2;
    int sum = 0, sum2 = 0;
    qsort(aliceSizes, aliceSizesSize, sizeof(int), cmp);
    qsort(bobSizes, bobSizesSize, sizeof(int), cmp);
    for (int i = 0; i < aliceSizesSize; i++)
    {
        sum += aliceSizes[i];
    }
    for (int i = 0; i < bobSizesSize; i++)
    {
        sum2 += bobSizes[i];
    }
    int n = sum - sum2;
    int i = 0, j = 0;
    for (i = 0, j = 0; i < aliceSizesSize && j < bobSizesSize;)
    {
        if (aliceSizes[i] - bobSizes[j] == n / 2)
            break;
        else if ((aliceSizes[i] - bobSizes[j]) < (n / 2))
        {
            i++;
        }
        else
        {
            j++;
        }
    }
    a[0] = aliceSizes[i];
    a[1] = bobSizes[j];
    return a;
}